#include <stdio.h>
#include <stdlib.h>
#include <string.h>


#define LEN sizeof(struct Student)


int n;

struct Student {
    long num;
    char name[20];
    float score[3];
    float ave;
    struct Student *next;
};


struct Student  *creat()
{
    struct Student  *head,*p1,*p2;
    n=0;
    p1=p2=(struct Student*)malloc(LEN);
    scanf("%ld,%f",&p1->num,&p1->score);
    head=NULL;
    while (p1->num!=0)
    {
        n=n+1;
        if (n==1) head=p1;
        else p2->next=p1;
        p2=p1;
        p1=(struct Student *)malloc(LEN);
        scanf("%ld,%f",&p1->num,&p1->score);
    }
    p2->next=NULL;


    return (head);
}

void main23() {
    struct Student *pt;
    pt = creat();
    printf("\nnum:%ld\nscore:%5.1f\n", pt->num, pt->score);




}


void main24() {
    char c;
    printf("Enter a character:");
    c = getchar();
    if (c >= '0' && c <= '9')printf("Digit!\n");
    else if (c >= 'A' && c <= 'Z')printf("Uppercase!\n");
    else if (c >= 'a' && c <= 'z')printf("Lowercase!\n");
    else printf("Other charater!\n");
}


#define N  10

void main25() {
    int a[N], i, j, min, temp;
    printf("请输入%d个数:\n", N);
    for (i = 0; i < N; i++)
        scanf("%d", a + i);
    for (i = 0; i < N - 1; i++) {
        min = i;
        for (j = i + 1; j < N; j++) {
            if (a[j] < a[min])
                min = j;
        }
        if (min != i) {
            temp = a[i];
            a[i] = a[min];
            a[min] = temp;
        }
    }
    for (i = 0; i < N; i++)
        printf("%d\n", a[i]);
}


int strstr_cnt(char *str, char *substr) {
    int count = 0;
    int m = strlen(str), n = strlen(substr);
    int i;
    for (i = 0; i < m + 1; i++) {
        if (str[i] == substr[0]) {
            int j;
            for (int j = 0; j < n + 1; j++) {
                if (str[i + j] == substr[j]) {
                    if (i + j > m)
                        break;
                } else
                    break;
                if (j == (n - 1))
                    count++;
            }
        } else
            continue;
    }
    return (count);
}

void main26() {
    FILE *fp;
    if ((fp = fopen("//sdcard//abc.txt", "r")) == NULL) {
        printf("not open file ");
        exit(0);
    }
    char str[60] = {0};
    char substr[5];
    fgets(str, 60, fp);
    puts(str);

    gets(substr);
    int nw;
    nw = strstr_cnt(str, substr);
    printf("%d\n", nw);
    getchar();
    int x = 0;
    while ((58 - x + 1) > 20) {
        if (str[x + 20] == '\0') {
            for (int i = x; i < x + 20; i++)
                printf("%c", str[i]);
            printf("\n");
            x = x + 21;
        } else {
            int i = (x + 19), j;
            while (str[i] == '\0')
                i--;
            for (j = x; j < i - 1; j++) {
                if (str[j] == '\0')
                    printf("\0\0");
                else
                    printf("%c", str[j]);
            }
            printf("\n");
            x = i - 1;
        }
    }
    for (; x < 59; x++) {
        printf("%c", str[x]);
    }
    fclose(fp);
    getchar();
}


int mainS() {
    int i, s;
    printf("选择求1长方体，2正方体，3三角形，4圆的面积");
    scanf("%d", &i);
    if (i == 1) {
        int a, b;
        printf("输入长方形长，宽");
        scanf("%d,%d", &a, &b);
        s = a * b;
    } else if (i == 2) {
        int a;
        printf("输入正方形边长");
        scanf("%d", &a);
        s = a * a;
    } else if (i == 3) {
        int a, b;
        printf("输入三角形底，高");
        scanf("%d,%d", &a, &b);
        s = a * b / 2;
    } else if (i == 4) {
        int r;
        printf("输入圆半径");
        scanf("%d", &r);
        s = r * r * 3.14;
    } else
        printf("输入错误");
    printf("面积%d\n", s);
    return 0;
}
int mainV() {
    int i, v;
    printf
            ("选择求1球，2圆柱，3圆锥，4正方体，5长方体的体积");
    scanf("%d", &i);
    if (i == 1) {
        int r;
        printf("输入球的半径");
        scanf("%d", &r);
        v = r * r * r * 3.14 * 3 / 4;
    } else if (i == 2) {
        int r, h;
        printf("输入圆柱的底面半径，高");
        scanf("%d,%d", &r, &h);
        v = r * r * h * 3.14;
    } else if (i == 3) {
        int r, h;
        printf("输入圆锥的底面半径，高");
        scanf("%d,%d", &r, &h);
        v = r * r * h * 3.14 / 3;
    } else if (i == 4) {
        int a;
        printf("输入正方体边长");
        scanf("%d", &a);
        v = a * a * a;
    } else if (i == 5) {
        int a, b, c;
        printf("输入长方体长，宽，高");
        scanf("%d,%d,%d", &a, &b, &c);
        v = a * b * c;
    } else
        printf("输入错误");
    printf("体积%d\n", v);
    return 0;
}
void main27() {
    int j;
    for (j = 0; j < 10; j++) {
        char x;
        printf("输入功能前的字母或数字\n");
        printf("选择求面积S，体积V\n");
        x = getchar();
        if (x == 'S') {
            mainS();
        } else if (x == 'V') {
            mainV();
        } else
            printf("输入错误\n");
    }
}


#define N 15

int main29()
{
    int a[N];
    int i,j,k,t;
    printf("输入数组\n");
    for (k=0;k<N;k++)
        scanf ("%d",&a[k]);
    for (i=0;i<N-1;i++)
        for (j=i+1;j<N;j++)
            if (a[i]>a[j])
            {
                t=a[i];
                a[i]=a[j];
                a[i]=t;
            }
    int flag=1,sign=1;
    int number;
    int loca,top,bott,mid;
    char c;
    while (flag)
    {
        printf("输入要找的数\n");
        scanf("%d",&number);
        loca=0;
        top=0;
        bott=N-1;
        if ((number<a[0])||(number>a[N-1]))
            loca=-1;
        while ((sign==1)&&(top<=bott)&&(loca>=0))
        {
            mid=(bott+top)/2;
            if (number==a[mid])
            {
                loca=mid;
                printf("\n找到了,数%d在数组的第%d位.\n",number,loca+1);
                sign=0;
            }
            else if (number<a[mid])
                bott=mid-1;
            else
                top=mid+1;
        }
        if (sign==1||loca==-1)
            printf("\n查无此数\n");
        printf("是否继续查找？(Y/N)\n");
        scanf(" \n%c",&c);
        printf("\n");
        if (c=='N'||c=='n')
            flag=0;
        else sign=1;
    }
    return 0;
}



void main30() {

    FILE *fp;
    int i, j, n, ni;
    char c[160], t, ch;
    if ((fp = fopen("A", "r")) == NULL) {
        printf("file A cannot be opened\n");
        exit(0);
    }
    printf("\n A contents are :\n");
    for (i = 0; (ch = fgetc(fp)) != EOF; i++) {
        c[i] = ch;
        putchar(c[i]);
    }
    fclose(fp);
    ni = i;
    if ((fp = fopen("B", "r")) == NULL) {
        printf("file B cannot be opened\n");
        exit(0);
    }
    printf("\n B contents are :\n");
    for (i = 0; (ch = fgetc(fp)) != EOF; i++) {
        c[i] = ch;
        putchar(c[i]);
    }
    fclose(fp);
    n = i;
    for (i = 0; i < n; i++)
        for (j = i + 1; j < n; j++)
            if (c[i] > c[j]) {
                t = c[i];
                c[i] = c[j];
                c[j] = t;
            }
    printf("\n C file is:\n");
    fp = fopen("C", "w");
    for (i = 0; i < n; i++) {
        putc(c[i], fp);
        putchar(c[i]);
    }
    fclose(fp);
    getchar();
}


void main22() {
    void main23();
}